<template>
  <div class="bgImg">
    <el-form :rules="rules" class="login-container" label-position="left" :model="loginForm"
            label-width="0px" v-loading="loading">
      <h3 class="login_title">高校公寓安检平台</h3>
      <el-form-item prop="uName">
        <el-input type="text" v-model="loginForm.uName" auto-complete="off" placeholder="用户名"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input type="password" v-model="loginForm.password" uto-complete="off" placeholder="密码"
                  @keyup.enter.native="submitClick"></el-input>
      </el-form-item>
      <el-form-item>
        <div  class="registerStyle">
          <router-link to='/register' style="text-decoration: none;">注册</router-link>
          <el-checkbox v-model="checked" >记住密码</el-checkbox>
        </div>
      </el-form-item>
      <el-form-item style="width: 100%">
        <el-button type="primary" style="width: 75%" @click="submitClick">登录</el-button>
      </el-form-item>
    </el-form>
  </div>

</template>
<script>
    export default {
        data() {
            return {
                rules: {
                    uName: [{required: true, message: '请输入用户名', trigger: 'blur'}],
                    password: [{required: true, message: '请输入密码', trigger: 'blur'}]
                },
                checked: true,
                loginForm: {
                    // uName: 'sysadmin',
                    // password: '123'
                },
                loading: false
            }
        },
        methods: {
            submitClick: function () {
                var _this = this;
                this.loading = true;
                this.postRequest('/login', {
                    uName: this.loginForm.uName,
                    password: this.loginForm.password
                }).then(resp => {
                    _this.loading = false;
                    if (resp && resp.status == 200) {
                        var info = JSON.stringify(resp.data.obj);
                        var data=resp.data
                        var userface=data.obj.userface
                        localStorage.setItem('userface',userface)//本地缓存头像
                        localStorage.setItem('info',info)
                        _this.$store.commit('login', data.obj);
                        var path = _this.$route.query.redirect;
                        _this.$router
                            .replace({path: path == '/' || path == undefined ? '/home' : path});

                    }
                });
            }
        }
    }
</script>
<style scoped>
  /* html{
    background-color: pink;
    height: 100%;
    width: 100%;
    position:absolute;
  } */
  .bgImg{
    background:url("../assets/bgImg.jpg") center center no-repeat;
    background-size: 100% 100%;
    position:fixed;
    height: 100%;
    width: 100%;
    /* background-color: pink; */
  }
  .registerStyle {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
  }

  .login-container {
    border-radius: 20px;
    background-clip: padding-box;
    margin: 180px auto;
    width: 420px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 2px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
  }

  .login_title {
    margin: 0px auto 40px auto;
    text-align: center;
    color: #505458;
  }

</style>
